package org.javaboy.fmall.utils.returnTool;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName ResTool
 * @Description 返回结果封装
 * @Author find me
 * @Date 2020/7/16 0016 0:51
 * @Version 1.0
 */
@Data
@AllArgsConstructor
//@NoArgsConstructor
public class ResTool<T> {

    /**
     * 接口状态
     */
    @ApiModelProperty("请求状态")
    private boolean success=true;

    /**
     * 错误码
     */
    @ApiModelProperty("错误码")
    private int code=200;

    /**
     * 成功消息
     */
    @ApiModelProperty("成功消息")
    private String msg = "";
    /**
     * 错误内容
     */
    @ApiModelProperty("错误内容")
    private String error = "";
    /**
     * 具体的内容
     */
    @ApiModelProperty("具体的内容")
    private T data;

    @ApiModelProperty("数据条数")
    private int total;

    public ResTool() {

    }

    public static ResTool ok = new ResTool();
    public static ResTool fail = new ResTool().code(-1);



    public static ResTool build() {
        return new ResTool();
    }


    public static <T> ResTool build(T data) {
        return new ResTool().data(data);
    }


    public ResTool code(int code) {
        this.code = code;
        return this;
    }

    public ResTool data(T data) {
        this.data = data;
        return this;
    }

    public ResTool msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResTool success(boolean success) {
        this.success = success;
        return this;
    }
    public ResTool error(String error) {
        this.error = error;
        return this;
    }
    public ResTool total(int total) {
        this.total = total;
        return this;
    }
}
